﻿<%@ Page Language="C#" EnableEventValidation="false" Async="true" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="SoftwareMonkeys.Scriptech.Diagnostics" %>  
<%@ Register Namespace="SoftwareMonkeys.Scriptech.Web" Assembly="SoftwareMonkeys.Scriptech.Web" TagPrefix="cc" %>
<script runat="server">
	protected string ScriptControlPath = String.Empty;
	protected string ScriptName = String.Empty;
	
	private void Page_Load(object sender, EventArgs e)
	{
        AddOnPreRenderCompleteAsync (
            new BeginEventHandler(BeginAsyncOperation),
            new EndEventHandler (EndAsyncOperation)
        );
	}
	
	private WebRequest _request;


    IAsyncResult BeginAsyncOperation (object sender, EventArgs e, 
        AsyncCallback cb, object state)
    {
    	string launchUrl = Request.Url.ToString().Replace("LaunchScriptAsync.aspx", "LaunchScript.aspx");
    
        _request = WebRequest.Create(launchUrl);
        return _request.BeginGetResponse (cb, state);
    }
    void EndAsyncOperation (IAsyncResult ar)
    {
        using (WebResponse response = _request.EndGetResponse(ar))
        {
            using (StreamReader reader = 
                new StreamReader(response.GetResponseStream()))
            {
            	while (reader.Peek() != -1)
            	{
                	string text = reader.ReadLine();
                	
                	Response.Write(text);
        			//OutputHolder.Controls.Add(new LiteralControl(text));
                }
            }
        }
        
    }
</script>
 


